/*
 * @Author: gk 
 * 树形编辑窗口
 * @Date: 2018-01-17 09:53:01 
 * @Last Modified by: gk
 * @Last Modified time: 2018-01-26 11:05:28
 */
layui.define(['zlConfig', 'zlContext', 'form'], function (exports) {
    var $ = layui.$
        , zlContext = layui.zlContext
        , zlConfig = layui.zlConfig
        , from = layui.form
        , statusName = zlConfig.global.result.statusName
        , msgName = zlConfig.global.result.msgName
        , dataName = zlConfig.global.result.dataName
        , ERROR = zlConfig.global.result.errorState
        , OK = zlConfig.global.result.okState
        , init = function (_this) {
            options = _this.config || {};
            var btnHtml = [];
            layui.use('zlComponentRender', function () {
                var $ = layui.$
                    , zlComponentRender = layui.zlComponentRender
                var formElems = zlComponentRender.forms(options, options.elem, options.tree.editForms);
               
                if (formElems && options.editType && options.editType === "edit") {
                    $.each(formElems, function (i, formElem) {
                        /**填充数据 */
                        $(formElems).attr("edit");
                        $.extend(options.data, options.params);
                        zlComponentRender.loadFormLocateData(options, formElem, options.tree.editForms[0], [options.data]);
                    });
                } else {
                    $.each(formElems, function (i, formElem) {
                        /**填充参数数据 */
                        $(formElems).attr("new");
                        zlComponentRender.loadFormLocateData(options, formElem, options.tree.editForms[0], [options.params]);
                    });
                }
            });
        }
        , zlTreeEditForm = {
            config: {},
            show: function (treeNode, options, params, editType) {
                var that = this;
                zlContext.showFormEx(1, window, options.title, options.width, options.height, '' //"/static/manager/functions/zlTreeEditForm.html?nodeId="+nodeId
                    , function () {
                    }, 0, function (layero, index) {
                        var tmpfig = {};
                        var contentElem = $(layero).find('.layui-layer-content');
                        $.extend(tmpfig, options);
                        tmpfig.elem = contentElem;
                        tmpfig.data = treeNode;
                        tmpfig.editType = editType;
                        tmpfig.params = params;
                        zlTreeEditForm.render(tmpfig, params);
                    });
            },
            /**渲染组件 */
            render: function (options, params) {
                var that = this;
                $.extend(that.config, options);
                that.config.id = zlContext.generateId();
                init(that);
            }
        };
    exports('zlTreeEditForm', zlTreeEditForm);
});